from windoh.control import Control
from windoh.controls.label import Label

class Button(Control):
    def __init__(self, **kwargs):
        Control.__init__(self, **kwargs)

    def on_mouse_press(self, x, y, b, m):
        if self._computed_style['border_style'] == 'outset':
            self.style['border_style'] = 'inset'
            self.style['old_border_style'] = 'outset'
        return True

    def on_mouse_release(self, x, y, b, m):
        self.dispatch_event('on_click')
        self.on_mouse_out()
        return True

    def on_mouse_out(self):
        Control.on_mouse_out(self)
        if self.style.has_key('old_border_style'):
            self.style['border_style'] = self.style['old_border_style']
            del self.style['old_border_style']

        
Button.register_event_type('on_click')


class TextButton(Button):
    class TextButtonLabel(Label):
        pass

    def __init__(self, label=None, **kwargs):
        Button.__init__(self, **kwargs)
        self._label = self.TextButtonLabel(label, left=0, right=0, 
            top=0, bottom=0)
        self.append(self._label)
        self._children_proxy = ()

    def on_pre_mouse_motion(self, x, y, dx, dy):
        Button.on_mouse_motion(self, x, y, dx, dy)
        return True

    def on_pre_mouse_press(self, x, y, b, m):
        return Button.on_mouse_press(self, x, y, b, m)

    def on_pre_mouse_release(self, x, y, b, m):
        return Button.on_mouse_release(self, x, y, b, m)
    
